<template>
  <div>
    <s-table ref="table" size="default" :rowKey="record => record.id" :columns="columns" :data="loadData" :pagination="paginationProps">
      <span slot="updateTime" slot-scope="text">{{ text | utc2beijing }}</span>
      <span slot="ifBox" slot-scope="text">{{ text | ifBox }}</span>
      <span slot="status" slot-scope="text">{{ text | senderType }}</span>
    </s-table>
  </div>
</template>
<script>
import { STable } from '../../../components'
import { getCommunicationByUnionId } from '@/api/box/member'
const columns = [
  {
    title: '沟通时间',
    dataIndex: 'updateTime',
    scopedSlots: { customRender: 'updateTime' }
  },
  {
    title: '沟通人',
    dataIndex: 'name'
  },
  {
    title: '状态',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '备注',
    dataIndex: 'remark',
    align: 'center'
  },
  {
    title: '是否要盒',
    dataIndex: 'ifBox',
    align: 'center',
    scopedSlots: { customRender: 'ifBox' }
  }
]
export default {
  components: {
    STable
  },
  data() {
    this.columns = columns
    return {
      unionId: '',
      paginationProps: {
        total: 0,
        showTotal: total => `共有 ${total} 条数据`
      },
      loadData: parameter => {
        let data = {
          page: parameter,
          requestData: {
            unionId: this.unionId
          }
        }
        return getCommunicationByUnionId(data).then(res => {
          if (res.code == 0) {
            return {
              data: res.data,
              page: res.page
            }
          } else {
            return {
              data: [],
              page: {
                pageNo: 0,
                count: 0,
                pageSize: 10
              }
            }
          }
        })
      }
    }
  },
  filters: {
    senderType(v) {
      if (v == 0) {
        return '联系失败'
      } else if (v == 1) {
        return '联系成功'
      }
    },
    ifBox(v) {
      if (v == 0) {
        return '否'
      } else {
        return '是'
      }
    }
  },
  created() {
    this.unionId = this.$route.params.id
  },
  beforeRouteLeave(to, from, next) {
    this.$destroy()
    next()
  }
}
</script>
